package servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import dao.CourseDao;
import dao.StudentDao;
import vo.Course;
import vo.Student;

/**
 * Servlet implementation class ManageCourseServlet
 */
public class OP_ManageCourseServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OP_ManageCourseServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		CourseDao coursedao = new CourseDao();
		try {
			ArrayList list = coursedao.getAllCourse();
			Course[] CourseArray=(Course[])list.toArray(new Course[list.size()]);
			//String jsonString = JSONArray.fromObject(StuArray).toString;
			Gson gson = new Gson();
			String jsonString = gson.toJson(CourseArray);
			System.out.print(gson.toJson(CourseArray));
			
			request.getSession().setAttribute("op_course_json", jsonString);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.getRequestDispatcher("/jsp/op/op_course.jsp").forward(request, response);//锟�
	}//内部跳转

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
